﻿Ext.ns('LEDAdvList');
LEDAdvList.version = 'Beta 1';
var g_LEDWindowObject;

function letallsettingswin(autoload) {
    function msgUpdateSuccess() {
        Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
        Ext.Msg.show({
            title: _CustomerConfigResource_Tip,
            msg: _CustomerConfigResource_Success,
            buttons: Ext.Msg.OK,
            animEl: 'elId',
            icon: Ext.MessageBox.INFO
        });
    };
    
    function msgUpdateFailure() {
        Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
        Ext.Msg.show({
            title: _CustomerConfigResource_Tip,
            msg: _CustomerConfigResource_Failure,
            buttons: Ext.Msg.OK,
            animEl: 'elId',
            icon: Ext.MessageBox.WARNING
        });
    }
    
    var pagesize = 65535;
    var ledadvfield = [{name:"choosed",type:"boolean"},
        "led_adv_id", 
        "sssid",
        "trackername",
        { name: "adv_address", type: "integer" },
        "advname",
        {name:"font",type:"integer"},
        "fontstring",
        {name:"color",type:"integer"},
        "colorstring",
        {name:"moving",type:"integer"},
        "movingstring",
        {name:"speed",type:"integer"},
        "speedstring",
        {name:"stay_time",type:"integer"},
        {name:"stop_model",type:"integer"},
        "stop_modelstring",
        {name:"start_date",type:"datetime"},
        {name:"stop_date",type:"datetime"},
        {name:"showtimes",type:"int"},
        {name:"usealllife",type:'boolean'},
        "usealllifestring",
        "timespans",
        "text",
        {name:"deviceaccepted",type:'boolean'}
    ];
    
    var ledsettingsfield = [{name:"choosed",type:"boolean"},
        "id", 
        "sssid",
        "trackername",
        "default_msg",
        {name:"default_msg_font",type:"integer"},
        "fontstring",
        {name:"default_msg_color",type:"integer"},
        "colorstring",
        {name:"default_msg_moving",type:"integer"},
        "movingstring",
        {name:"default_msg_speed",type:"integer"},
        "speedstring",
        {name:"default_msg_stay_time",type:"integer"},
        {name:"default_msg_stop_model",type:"integer"},
        "stop_modelstring",
        {name:"default_msg_showtype",type:"integer"},
        "showtypestring",
        {name:"led_time",type:"datetime"},
        {name:"light_level",type:"integer"},
        {name:"poweron_waittime",type:"integer"},
        {name:"autoopen_time",type:"datetime"},
        {name:"autoclose_time",type:"datetime"},
        {name:"auto_open_close",type:"boolean"},
        {name:"show_alarm_type",type:"integer"},
        "alarm_msg",
        {name:"alarm_time",type:"integer"},
        
        {name:"immi_msg_level",type:"integer"},
        {name:"immi_msg_exitway",type:"integer"},
        {name:"immi_msg_font",type:"integer"},
        {name:"immi_msg_color",type:"integer"},
        {name:"immi_msg_moving",type:"integer"},
        {name:"immi_msg_speed",type:"integer"},
        {name:"immi_msg_stay_time",type:"integer"},
        {name:"immi_msg_show_times",type:"integer"},
        {name:"immi_msg_life_time",type:"integer"},
        {name:"immi_msg_stop_model",type:"integer"},
        {name:"immi_msg_show_time",type:"integer"},
        "immi_msg",
        
        {name:"default_msg_accepted",type:'boolean'},
        {name:"alarm_msg_accepted",type:'boolean'},
        {name:"immi_msg_accepted",type:'boolean'}
    ];
    
    var panelledparamscolumn1 = new Ext.Panel({
        layout: 'form',
        border: false,
        width: 290,
        labelWidth: 70,
        autoHeight: true,
        items: []
    });
    
    
    
    function disableLEDAllParamPanel() {
        if (panelledparamscolumn1 != null)
            panelledparamscolumn1.removeAll();
        
    }
    
    function reshowledparams() {
        disableLEDAllParamPanel();
        panelledparams.show();
        
    }

    function redoledlayoutparams() {
        panelledparamscolumn1.doLayout();
       
        //panelledparams.setHeight(panelledallcommand.getHeight()-200);
    }
    

    
    function createNewParamAndShow(paramfieldtype, captext, maxlen, unittext, cmbstore,name,id) {
        var r;
        if (unittext.length == 0)
            unittext = " "; //give a space if text is empty
        var lblunit = createNewParamUnitLabel(unittext);
        if (paramfieldtype == EnumParamFieldType.TextField)
            r = createNewParamTextField(captext, maxlen,false,null,name);
        else if (paramfieldtype == EnumParamFieldType.NumberField)
            r = createNewParamNumberField(captext, maxlen);
        else if (paramfieldtype == EnumParamFieldType.ComboBoxField) {
            r = createNewParamCmbField(cmbstore, captext);
            r.setValue(cmbstore.getAt(0).get(r.valueField));
        }
        else if (paramfieldtype == EnumParamFieldType.MultiComboBoxField) {
            r = createNewMultiParamCmbField(cmbstore, captext);
        }
        else if (paramfieldtype == EnumParamFieldType.TextArea) {
            r = createNewParamTextArea(captext, maxlen);
        }
        else if(paramfieldtype == EnumParamFieldType.Date){
            r = createNewParamDate(captext,false,id);
        }
        else if(paramfieldtype == EnumParamFieldType.Time){
            r = createNewParamTime(captext,false,id);
        }
        if (!Ext.isEmpty(name))
            r.name = name;
        panelledparamscolumn1.add(r);
        //panelparamscolumn2.add(lblunit);
        return r;
    }

    
//    var trackNameLEDAdvCombo = getTrackerCheckboxCombo(true);
//    var trackNameLEDDefaultCombo = getTrackerCheckboxCombo(true);
//    var trackNameLEDImmiCombo = getTrackerCheckboxCombo(true);
//    var trackNameAlarmCombo = getTrackerCheckboxCombo(true);
    
    var ledadvstore = new Ext.data.GroupingStore({
	   proxy:new Ext.data.HttpProxy({
            url:"HandlerLEDAdv",
            method:"POST",
            timeout:120000
       }),
       reader:new Ext.data.JsonReader({
			fields:ledadvfield,
            root:"data",
            totalProperty: "totalCount"
       }),
       sortInfo:{field: 'trackername', direction: "ASC"},
       groupField:'trackername'
   });
   
   var leddefaultmsgstore = new Ext.data.GroupingStore({
	   proxy:new Ext.data.HttpProxy({
            url:"HandlerLEDSettings",
            method:"POST",
            timeout:120000
       }),
       reader:new Ext.data.JsonReader({
			fields:ledsettingsfield,
            root:"data",
            totalProperty: "totalCount"
       }),
       sortInfo:{field: 'trackername', direction: "ASC"}
   });
   
   //leddefaultmsgstore.load();
   
   var ledalarmmsgstore = new Ext.data.GroupingStore({
	   proxy:new Ext.data.HttpProxy({
            url:"HandlerLEDSettings",
            method:"POST",
            timeout:120000
       }),
       reader:new Ext.data.JsonReader({
			fields:ledsettingsfield,
            root:"data",
            totalProperty: "totalCount"
       }),
       sortInfo:{field: 'trackername', direction: "ASC"}
   });
   
   //ledalarmmsgstore.load();
   
   var ledimmimsgstore = new Ext.data.GroupingStore({
	   proxy:new Ext.data.HttpProxy({
            url:"HandlerLEDSettings",
            method:"POST",
            timeout:120000
       }),
       reader:new Ext.data.JsonReader({
			fields:ledsettingsfield,
            root:"data",
            totalProperty: "totalCount"
       }),
       sortInfo:{field: 'trackername', direction: "ASC"}
   });
   //ledimmimsgstore.load();
   
   var grdledadvviewgroup = new Ext.grid.GroupingView({
        startCollapsed: false,
        //forceFit:true,
        groupTextTpl: '{gvalue}'
    });
   
    var stofont = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[0,_LED_Font_Sim],[1,_LED_Font_Blod]] //,[2,_LED_Font_Song],[3,_LED_Font_Hei],[4,_LED_Font_Kai],[5,_LED_Font_XinSong]] 不支持
    });
     var stocolor = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[1,_Color_Red],[2,_Color_Yellow],[3,_Color_Green],[4,_Color_AntiRed],[5,_Color_AntiYellow]]
    });
    var stomove = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[1, _LED_MoveLeft], [3, _LED_MoveUp], [4, _LED_MoveDown], [5, _LED_Keep]]//[2,_LED_MoveRight]不支持
    });
    var stospeed = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[0,_LED_Speed0],[1,_LED_Speed1],[2,_LED_Speed2],[3,_LED_Speed3],[4,_LED_Speed4]]
    });
    var stostoptype= new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[0,_LED_StopModel1],[1,_LED_StopModel2]]
    });
//    var stoyesno = new Ext.data.ArrayStore({
//        fields:[{name:'valueid',type:'integer'},'val'],
//        data:[[0,_TrackerMain_No],[1,_TrackerMain_Yes]]
//    });
//    
    
   ledadvstore.addListener('load', function(store, records) {
        ledadvstore.each(function(record){
            record.set('fontstring',stofont.getAt(stofont.findExact('valueid',record.get('font'))).get('val'));
            if(stocolor.findExact('valueid',record.get('color')) == -1)
                record.set('colorstring', _Color_Red);
            else
                record.set('colorstring',stocolor.getAt(stocolor.findExact('valueid',record.get('color'))).get('val'));
            if(stomove.findExact('valueid',record.get('moving')) == -1)
                record.set('movingstring',_LED_MoveLeft);
            else
                record.set('movingstring',stomove.getAt(stomove.findExact('valueid',record.get('moving'))).get('val'));
            record.set('speedstring',stospeed.getAt(stospeed.findExact('valueid',record.get('speed'))).get('val'));
            record.set('stop_modelstring',stostoptype.getAt(stostoptype.findExact('valueid',record.get('stop_model'))).get('val'));
            //record.set('usealllifestring',stoyesno.getAt(stoyesno.findExact('valueid',record.get('usealllife'))).get('val'));
            if(record.get('usealllife')){
                record.set('usealllifestring',_TrackerMain_Yes);
                record.set('start_date','-');
                record.set('stop_date','-');
            }
            else
                record.set('usealllifestring',_TrackerMain_No);
        });
   });
   
   ledadvstore.on('beforeload',function(store){
        ledadvstore.baseParams = {sssids: ""} 
   });


   var txtAdvName = new Ext.form.TextField({ });
   var txtSearchAdv = new Ext.form.TextField({ });
   var txtSearchDefault = new Ext.form.TextField({});
   var txtSearchAlarm = new Ext.form.TextField({});
   var txtSearchImmi = new Ext.form.TextField({});
   
   
   var tbarLEDDefault = new Ext.Toolbar({
        items:[
            _TrackerMain_Keywords+':',
            txtSearchDefault,
            {
                tooltip: { text: _TrackerMain_Search, autoHide: true },
                icon: 'images/search16.gif',
                handler: function() {
                    leddefaultmsgstore.reload({
                        params: {
                            event:"search",
                            type:"default",
                            //sssids: trackNameLEDDefaultCombo.getValue(),
                            trackername:txtSearchLEDDeviceKey.getValue(),
                            content:txtSearchDefault.getValue(),
                            start: 0,
                            limit: pagesize
                        }
                    });
                }
            }
        ]
   });
   
   var tbarLEDAlarm = new Ext.Toolbar({
        items:[
            _TrackerMain_Keywords+':',
            txtSearchAlarm,
            {
                tooltip: { text: _TrackerMain_Search, autoHide: true },
                icon: 'images/search16.gif',
                handler: function() {
                    ledalarmmsgstore.reload({
                        params: {
                            event:"search",
                            type:"alarm",
                            //sssids: trackNameAlarmCombo.getValue(),
                            trackername:txtSearchLEDDeviceKey.getValue(),
                            content:txtSearchAlarm.getValue(),
                            start: 0,
                            limit: pagesize
                        }
                    });
                }
            }
        ]
   });
   
   var tbarLEDImmi = new Ext.Toolbar({
        items:[
            _TrackerMain_Keywords+':',
            txtSearchImmi,
            {
                tooltip: { text: _TrackerMain_Search, autoHide: true },
                icon: 'images/search16.gif',
                handler: function() {
                    ledimmimsgstore.reload({
                        params: {
                            event:"search",
                            type:"immi",
                            //sssids: trackNameLEDImmiCombo.getValue(),
                            trackername:txtSearchLEDDeviceKey.getValue(),
                            content:txtSearchImmi.getValue(),
                            start: 0,
                            limit: pagesize
                        }
                    });
                }
            }
        ]
   });
   
   this.searchLEDAdv = function(){
        ledadvstore.reload({
            params: {
                event:"search",
                //sssids: trackNameLEDAdvCombo.getValue(),
                //advname:txtAdvName.getValue(),
                trackername:txtSearchLEDDeviceKey.getValue(),
                content:txtSearchAdv.getValue(),
                start: 0,
                limit: pagesize
            }
        });
   };
   
   var tbarLEDAdv = new Ext.Toolbar({
        items: [
            _TrackerMain_Keywords+':',
            txtSearchAdv,
            {
                tooltip: { text: _TrackerMain_Search, autoHide: true },
                icon: 'images/search16.gif',
                handler: function() {
                    g_LEDWindowObject.searchLEDAdv();
                }
            },{
                tooltip:{text:_CustomerConfigResource_AddNew,autoHide:true},
                icon: 'images/add.png',
                handler:function(){
                    addnewledadvwin();
                }
            },{
                tooltip:{text:_LED_EditAdv,autoHide:true},
                icon: 'images/edit.gif',
                handler:function(){
                    var sssidarray = [];
                    var advaddressarray =[];
                    ledadvstore.each(function(record){
                        if(record.get('choosed')){
                            sssidarray.push(record.get("sssid"));
                            advaddressarray.push(record.get("adv_address"));
                        }
                    });
                    if(sssidarray.length == 0){
                        Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
                        Ext.Msg.show({
                            title: _POI_SelectAtLeastOne,
                            msg: _POI_SelectAtLeastOne,
                            buttons: Ext.Msg.OK,
                            animEl: 'elId',
                            icon: Ext.MessageBox.WARNING
                        });
                    }
                    else
                        addnewledadvwin(sssidarray,advaddressarray);
                }
            },{
                tooltip: { text:_CustomerConfigResource_Delete, autoHide: true },
                icon: 'images/delete.png',
                handler: function() {
                    Ext.MessageBox.YESNO = { yes: _TrackerMain_Yes, no: _TrackerMain_No };
                    Ext.MessageBox.confirm(_TrackerMain_Title, _Photo_SureToDelete, function(btn){
                        if (btn == "yes") {
                            adveditor.stopEditing();
                            Ext.MessageBox.show({
                                msg: _CustomerConfigResource_Deleting,
                                progressText: _CustomerConfigResource_Deleting,
                                width: 300,
                                wait: true,
                                waitConfig: { interval: 200 }
                            });
                            var splitIds = "";
                            var sssids = "";
                            var advaddresses ="";
                            ledadvstore.each(function(record){
                                if(record.get('choosed')){
                                    if (splitIds.length =="") {
                                        splitIds = record.get("led_adv_id");
                                        sssids =  record.get("sssid");
                                        advaddresses = record.get("adv_address");
                                    }
                                    else {
                                        splitIds += "," + record.get("led_adv_id");
                                        sssids +="," +  record.get("sssid");
                                        advaddresses += "," + record.get("adv_address");
                                    }
                                }
                                
                            });
                            if(sssids ==""){
                                Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
                                Ext.Msg.show({
                                    title: _POI_SelectAtLeastOne,
                                    msg: _POI_SelectAtLeastOne,
                                    buttons: Ext.Msg.OK,
                                    animEl: 'elId',
                                    icon: Ext.MessageBox.WARNING
                                });
                            }
                            else{
                                Ext.Ajax.request({
                                    url: 'HandlerLEDAdv',
                                    success: function(result) {
                                        Ext.MessageBox.hide();
                                        var flag = eval(result.responseText);
                                        if (flag != "false") {
                                            ledadvstore.each(function(r){
                                                if(r.get('choosed'))
                                                    ledadvstore.remove(r);
                                            });
                                            Ext.Msg.alert(_CustomerConfigResource_Tip, _CustomerConfigResource_Deleted);
                                        }
                                        else {
                                            Ext.Msg.alert(_CustomerConfigResource_Tip, _RouteResources_Failed);
                                        }
                                    },
                                    failure: function() {
                                        Ext.MessageBox.hide();
                                        Ext.Msg.alert(_CustomerConfigResource_Tip, _RouteResources_Failed);
                                    },
                                    params: {
                                        event:"delete",
                                        advids: splitIds,
                                        sssids:sssids,
                                        advaddresses:advaddresses
                                    }
                                });
                            }
                        }
                    });
                }
            }
       ]
   });
   
  
   function handlerChange(){
 //       if (isUnicode(txtadvtext.getValue()))
            txtadvtext.maxLength = 128;
//        else
//            txtadvtext.maxLength = 256; //暂时不支持英文２５６
   }
   
   var btnSelectAll = new Ext.Button({
        text: _Photo_SelectAll,
        style: 'margin-right:16px',
        width: 80,
        handler: function() {
            ledadvstore.each(function(record) {
                record.set("choosed", true);
            });
        }
    });

    var btnSelectNone = new Ext.Button({
        text: _Photo_SelectNone,
        style: 'margin-right:16px',
        width: 80,
        handler: function() {
            ledadvstore.each(function(record) {
                record.set("choosed", false);
            });
        }
    });
    
       
  
   ledadvstore.on('update',function(){
        var hasonechoosed = false;
         ledadvstore.each(function(record) {
            if(record.get('choosed')){
                hasonechoosed = true;
                return;
            }
         });
         
    });
    
   var chooseboxled = new Ext.form.Checkbox({
        allowBlank: true,
        maxLength:3
   });
   
    var chkLEDSelection = new Ext.grid.CheckColumn({
       header: '',
       width:25,
       sortable: false,
       dataIndex: 'choosed',
       editor:chooseboxled
    });
    
     var txtadvtext = new Ext.form.TextField({
        allowBlank: false,
        blankText: _NewForText_Confirm,
        maxLength:128,
        listeners: {
            render: function(c) {
              c.getEl().on({
                change: handlerChange,
                scope: c
              });
            }
        }
    });
    
    function getFontFromValue(value){
        if(value == 0)
            return _LED_Font_Sim;
        else
            return _LED_Font_Blod;
    }
    
    function getDeviceAcceptFromValue(value){
        if(value)
            return _LED_Device_Accepted;
        else
            return _LED_Device_Not_Accepted;
    }
    
    function getMoveDirectionFromValue(value){
        if(value == 1)
            return  _LED_MoveLeft;
        else if (value == 3)
            return  _LED_MoveUp;
        else if (value == 4)
            return  _LED_MoveDown;
        else if(value ==5)
            return  _LED_Keep;
        else
            return _LED_MoveLeft;
    }
    
    function getSpeedFromValue(value){
        if(value ==0)
            return _LED_Speed0;
        else if(value == 1)
            return _LED_Speed1;
        else if(value == 2)
            return _LED_Speed2;
        else if(value == 3)
            return _LED_Speed3;
        else if(value == 4)
            return _LED_Speed4;
        else
            return _LED_Speed0;
    }
   
    function getStopModelFromValue(value){
        if(value ==0)
            return _LED_StopModel1;
        else if(value == 1)
            return _LED_StopModel2;
        else
            return _LED_StopModel1;
    }
    
    function getShowTypeFromValue(value){
        if(value==0)
            return _LED_ShowSysTime;
        else if(value==1)
            return _LED_ShowDefaultText;
        else
            return _LED_ShowSysTime;
    }
    
//    var cmLEDAdv = new Ext.grid.ColumnModel({
//        columns: [
//            chkLEDSelection,
//            this.actions,
//             {
//                header: _Alarm_Header_Name,
//                dataIndex: 'trackername',
//                width: 150
//            },{
//                header: _LED_MailboxNumber,
//                dataIndex: 'adv_address',
//                width: 70
//            },{
//                header: _LED_Accepted,
//                dataIndex: 'deviceaccepted',
//                width: 50,
//                renderer:function(value, metaData, record, rowIndex, colIndex, store){
//                    if(value)
//                        return _LED_Device_Accepted;
//                    else
//                        return _LED_Device_Not_Accepted;
//                }
//            }, {
//                header: _LED_AdvName,
//                dataIndex: 'advname',
//                width: 150
//            },
////            {
////                header: _Color,
////                dataIndex: 'colorstring',
////                width: 70
////            },
//            {
//                header:_LED_AllLife,
//                dataIndex:'usealllifestring',
//                width:100
//            },{
//                header: _LED_StartDate,
//                dataIndex: 'start_date',
//                width: 100
//            },{
//                header: _LED_StopDate,
//                dataIndex: 'stop_date',
//                width: 100
//            },{
//                header: _LED_Body,
//                dataIndex: 'text',
//                width: 150,
//                //editor: txtadvtext,
//                fixed:false
//            },{
//                header:_LED_TimeSpan,
//                dataIndex:'timespans',
//                width:100
//            },{
//                header: _LED_MoveDirection,
//                dataIndex: 'movingstring',
//                width: 70
//            },{
//                header: _LED_Speed,
//                dataIndex: 'speedstring',
//                width: 70
//            },{
//                header: _LED_KeepTime,
//                dataIndex: 'stay_time',
//                width: 70
//            },{
//                header: _LED_StopModel,
//                dataIndex: 'stop_modelstring',
//                width: 100
//            },{
//                header: _LED_ShowTimes,
//                dataIndex: 'showtimes',
//                width: 70
//            }, {
//                header: _LED_Font,
//                dataIndex: 'fontstring',
//                width: 70
//            }
//        ],
//        defaults: {
//            sortable: true,
//            menuDisabled: true,
//            width: 75
//        }
//    });
    
    var cmLEDDefaultMsg= new Ext.grid.ColumnModel({
        columns: [{
                header: _Alarm_Header_Name,
                dataIndex: 'trackername',
                width: 150
            },{
                header: _LED_Accepted,
                dataIndex: 'default_msg_accepted',
                width: 50,
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getDeviceAcceptFromValue(value);
                }
            },{
                header: _LED_Body,
                dataIndex: 'default_msg',
                width: 150
            },{
                header: _LED_Font,
                dataIndex: 'default_msg_font',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getFontFromValue(value);
                },
                width: 100
            },{
                header: _LED_MoveDirection,
                dataIndex: 'default_msg_moving',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getMoveDirectionFromValue(value);
                },
                width: 100
            },{
                header: _LED_Speed,
                dataIndex: 'default_msg_speed',
                 renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getSpeedFromValue(value);
                },
                width: 100
            },{
                header: _LED_KeepTime,
                dataIndex: 'default_msg_stay_time',
                width: 100
            },{
                header:_LED_StopModel,
                dataIndex: 'default_msg_stop_model',
                 renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getStopModelFromValue(value);
                },
                width: 100
            },{
                header: _LED_DefaultShowType,
                dataIndex: 'default_msg_showtype',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getShowTypeFromValue(value);
                },
                width: 100
            }
        ],
        defaults: {
            sortable: true,
            menuDisabled: true,
            width: 75
        }
    });
    
    var cmLEDImmiMsg= new Ext.grid.ColumnModel({
         columns: [{
                header: _Alarm_Header_Name,
                dataIndex: 'trackername',
                width: 150
            },{
                header: _LED_Accepted,
                dataIndex: 'immi_msg_accepted',
                width: 50,
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getDeviceAcceptFromValue(value);
                }
            },{
                header: _LED_Body,
                dataIndex: 'immi_msg',
                width: 150
            },{
                header: _LED_ShowLevel,
                dataIndex: 'immi_msg_level',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    if(value == 0)
                        return _LED_Normal;
                    else(value == 1)
                        return _LED_Urgent;
                },
                width: 100
            },{
                header: _LED_Font,
                dataIndex: 'immi_msg_font',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getFontFromValue(value);
                },
                width: 100
            },{
                header: _LED_MoveDirection,
                dataIndex: 'immi_msg_moving',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getMoveDirectionFromValue(value);
                },
                width: 100
            },{
                header: _LED_Speed,
                dataIndex: 'immi_msg_speed',
                 renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getSpeedFromValue(value);
                },
                width: 100
            },{
                header: _LED_KeepTime,
                dataIndex: 'immi_msg_stay_time',
                width: 100
            }
            ,{
                header:_LED_ShowTimes,
                dataIndex:'immi_msg_show_times',
                width: 100
            },{
                header:_LED_LifeTime,
                dataIndex:'immi_msg_life_time',
                width: 150
                ,renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    var v1 = padLeft((value/60).toString(),'0',2);
                    var v2 = padLeft((value%60).toString(),'0',2);
                    return v1+":" +v2;
                }
            },{
                header:_LED_ImmiShowTime,
                dataIndex:'immi_msg_show_time',
                width:100
                
            },{
                header:_LED_StopModel,
                dataIndex: 'immi_msg_stop_model',
                 renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    return getStopModelFromValue(value);
                },
                width: 180
            },{
                header: _LED_DefaultShowType,
                dataIndex: 'immi_msg_exitway',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    if(value == 0)
                        return _LED_ExitType1;
                    else if(value == 1)
                        return _LED_ExitType2;
                    else if(value == 2)
                        return _LED_ExitType3;
                    else if(value == 3)
                        return _LED_ExitType4;
                    else
                        return _LED_ExitType1;
                },
                width: 100
            }]
        ,defaults: {
            sortable: true,
            menuDisabled: true,
            width: 75
        }
    }); 
    
    var cmLEDAlarmMsg= new Ext.grid.ColumnModel({
        columns: [{
                header: _Alarm_Header_Name,
                dataIndex: 'trackername',
                width: 150
            },{
                header: _LED_Accepted,
                dataIndex: 'alarm_msg_accepted',
                width: 50,
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    if(value)
                        return _LED_Device_Accepted;
                    else
                        return _LED_Device_Not_Accepted;
                }
            },{
                header:_LED_RFlag,
                dataIndex:'show_alarm_type',
                renderer:function(value, metaData, record, rowIndex, colIndex, store){
                    if(value == 0){
                        return _LED_AlarmType1;
                    }
                    else if(value == 1)
                        return _LED_AlarmType2;
                },
                width:300
            },{
                header: _LED_AlarmText,
                dataIndex: 'alarm_msg',
                width: 350
            }]
        ,defaults: {
            sortable: true,
            menuDisabled: true,
            width: 75
        }
    
    });
    
    var adveditor = new Ext.ux.grid.RowEditor({
        saveText: _CustomerConfigResource_Update,
        cancelText: _CustomerConfigResource_Cancel,
        listeners: {
            afteredit: function(object, changes, r, rowIndex) {
                updateLEDAdv();
            }
        }
    });

    LEDAdvList.Grid = Ext.extend(Ext.grid.EditorGridPanel, {
        initComponent: function() {
           this.action = new Ext.ux.grid.RowActions({
                  header:''
                  ,autoWidth:true
    //          ,hideMode:'display'
                ,keepSelection:false
                ,actions:[{
                    iconCls:'icon-led-edit'
                    ,tooltip:_LED_EditAdv
                },{
                    iconCls:'icon-led-del'
                    ,tooltip:_CustomerConfigResource_Delete
                }]
//                ,groupActions:[{
//				     iconCls:'icon-led-aa'
//				    ,qtip:'Remove Table'
//			    }]
                ,callbacks:{
                    'icon-led-edit':function(grid, record, action, row, col) {
                        
                    }
                }
            });
            this.action.on({
                action:function(grid, record, action, row, col) {
                    //Ext.ux.Toast.msg('Event: action', 'You have clicked row: <b>{0}</b>, action: <b>{1}</b>', row, action);
                    if(action == 'icon-led-edit'){
                        var sssidarray = [];
                        var advaddressarray=[];
                        sssidarray.push(record.get('sssid'));
                        advaddressarray.push(record.get('adv_address'));
                        addnewledadvwin(sssidarray,advaddressarray,record);
                    }
                    else if(action == 'icon-led-del'){
                        Ext.MessageBox.YESNO = { yes: _TrackerMain_Yes, no: _TrackerMain_No };
                        Ext.MessageBox.confirm(_TrackerMain_Title, _Photo_SureToDelete, function(btn){
                            if (btn == "yes") {
                                adveditor.stopEditing();
                                Ext.MessageBox.show({
                                    msg: _CustomerConfigResource_Deleting,
                                    progressText: _CustomerConfigResource_Deleting,
                                    width: 300,
                                    wait: true,
                                    waitConfig: { interval: 200 }
                                });
                               
                                Ext.Ajax.request({
                                    url: 'HandlerLEDAdv',
                                    success: function(result) {
                                        Ext.MessageBox.hide();
                                        var flag = eval(result.responseText);
                                        if (flag != "false") {
                                            ledadvstore.remove(record);
                                            Ext.Msg.alert(_CustomerConfigResource_Tip, _CustomerConfigResource_Deleted);
                                        }
                                        else {
                                            Ext.Msg.alert(_CustomerConfigResource_Tip, _RouteResources_Failed);
                                        }
                                        ledadvstore.remove(record);
                                    },
                                    failure: function() {
                                        Ext.MessageBox.hide();
                                        Ext.Msg.alert(_CustomerConfigResource_Tip, _RouteResources_Failed);
                                    },
                                    params: {
                                        event:"delete",
                                        advids: record.get('led_adv_id'),
                                        sssids: record.get('sssid'),
                                        advaddresses:record.get('adv_address')
                                    }
                                });
                                
                            }
                        });
                    }
                }
//                ,beforeaction:function() {
//                    Ext.ux.Toast.msg('Event: beforeaction', 'You can cancel the action by returning false from this event handler.');
//                }
//                ,beforegroupaction:function() {
//                    Ext.ux.Toast.msg('Event: beforegroupaction', 'You can cancel the action by returning false from this event handler.');
//                }
//                ,groupaction:function(grid, records, action, groupId) {
//                    Ext.ux.Toast.msg('Event: groupaction', 'Group: <b>{0}</b>, action: <b>{1}</b>, records: <b>{2}</b>', groupId, action, records.length);
//                }
            });
            Ext.apply(this, {
                //colModel: cmLEDAdv,
                colModel: new Ext.grid.ColumnModel({
                    columns: [
                        chkLEDSelection,
                        this.action,
                         {
                            header: _Alarm_Header_Name,
                            dataIndex: 'trackername',
                            width: 150
                        },{
                            header: _LED_MailboxNumber,
                            dataIndex: 'adv_address',
                            width: 70
                        },{
                            header: _LED_Accepted,
                            dataIndex: 'deviceaccepted',
                            width: 50,
                            renderer:function(value, metaData, record, rowIndex, colIndex, store){
                                if(value)
                                    return _LED_Device_Accepted;
                                else
                                    return _LED_Device_Not_Accepted;
                            }
                        }, {
                            header: _LED_AdvName,
                            dataIndex: 'advname',
                            width: 150
                        },
            //            {
            //                header: _Color,
            //                dataIndex: 'colorstring',
            //                width: 70
            //            },
                        {
                            header:_LED_AllLife,
                            dataIndex:'usealllifestring',
                            width:100
                        },{
                            header: _LED_StartDate,
                            dataIndex: 'start_date',
                            width: 100
                        },{
                            header: _LED_StopDate,
                            dataIndex: 'stop_date',
                            width: 100
                        },{
                            header: _LED_Body,
                            dataIndex: 'text',
                            width: 150,
                            //editor: txtadvtext,
                            fixed:false
                        },{
                            header:_LED_TimeSpan,
                            dataIndex:'timespans',
                            width:100
                        },{
                            header: _LED_MoveDirection,
                            dataIndex: 'movingstring',
                            width: 70
                        },{
                            header: _LED_Speed,
                            dataIndex: 'speedstring',
                            width: 70
                        },{
                            header: _LED_KeepTime,
                            dataIndex: 'stay_time',
                            width: 70
                        },{
                            header: _LED_StopModel,
                            dataIndex: 'stop_modelstring',
                            width: 100
                        },{
                            header: _LED_ShowTimes,
                            dataIndex: 'showtimes',
                            width: 70
                        }, {
                            header: _LED_Font,
                            dataIndex: 'fontstring',
                            width: 70
                        }
                    ],
                    defaults: {
                        sortable: true,
                        menuDisabled: true,
                        width: 75
                    }
                }),
                plugins: [chkLEDSelection, this.action],
                view: grdledadvviewgroup,
                stripeRows: true,
                listeners: {
                    load: { scope: this, fn: function() {
                        this.getSelectionModel().selectFirstRow();
                    }
                    }
                }
            });
            LEDAdvList.Grid.superclass.initComponent.apply(this, arguments);
        }
        , onRender: function() {
            LEDAdvList.Grid.superclass.onRender.apply(this, arguments);
            
        }
    });

    var grdAdv = new LEDAdvList.Grid({
        region:'center',
        tbar: tbarLEDAdv,
        store: ledadvstore,  
        stripeRows: true,
        loadMask: true,
        //width:605,
        //height:620,
        clicksToEdit: 2,
        
        buttons:[btnSelectAll,btnSelectNone],
        selModel:new Ext.grid.RowSelectionModel({singleSelect : true})
    });
    
    grdAdv.addListener('render', function(grid) {
        var store = grid.getStore();  // Capture the Store.   
        var view = grid.getView();    // Capture the GridView.
        grid.tip = new Ext.ToolTip({
            target: view.mainBody,    // The overall target element.
            //delegate: '.x-grid3-row', // Each grid row causes its own seperate show and hide.   
            delegate: '.x-grid3-cell', // Each grid cell causes its own seperate show and hide.   
            trackMouse: true,         // Moving within the row should not hide the tip.   
            renderTo: document.body,  // Render immediately so that tip.body can be referenced prior to the first show.   
            listeners: {              // Change content dynamically depending on which element triggered the show.   
                beforeshow: function updateTipBody(tip) {
                    var rowIndex = view.findRowIndex(tip.triggerElement);
                    var cellIndex = view.findCellIndex(tip.triggerElement);
//                    var cell = view.getCell(rowIndex, cellIndex);  
//                    tip.body.dom.innerHTML = cell.innerHTML; 
                    if(cellIndex != 1){
                       tip.body.dom.innerHTML =_LED_AdvTip;
                       return true;
                    }
                    else{
                        return false;
                    }                    
                      
                }
            }
        });
    });
    
    var grdDefaultMsg = new Ext.grid.GridPanel({
        region:'center',
        colModel:cmLEDDefaultMsg,
        tbar: tbarLEDDefault,
        store: leddefaultmsgstore,  
        stripeRows: true,
        loadMask: true,
        selModel:new Ext.grid.RowSelectionModel({singleSelect : true})
    });
    
    

    var grdImmiMsg = new Ext.grid.GridPanel({
        region:'center',
        colModel:cmLEDImmiMsg,
        tbar: tbarLEDImmi,
        store: ledimmimsgstore,  
        stripeRows: true,
        loadMask: true,
        selModel:new Ext.grid.RowSelectionModel({singleSelect : true})
    }); 
    
   
    
    var grdAlarmMsg = new Ext.grid.GridPanel({
        region:'center',
        colModel:cmLEDAlarmMsg,
        tbar: tbarLEDAlarm,
        store: ledalarmmsgstore,  
        stripeRows: true,
        loadMask: true,
        selModel:new Ext.grid.RowSelectionModel({singleSelect : true})
    }); 
    
    var panelLEDAlarmCommandParams = new Ext.Panel({
        border:false,
        layout:'column',
        width:300,
        height:80
    });
    
   
    
   

    grdAdv.addListener("rowdblclick", function(grid, index) {
        var record = grid.getSelectionModel().getSelections()[0];
        var sssidarray = [];
        var advaddressarray=[];
        sssidarray.push(record.get('sssid'));
        advaddressarray.push(record.get('adv_address'));
        addnewledadvwin(sssidarray,advaddressarray,record);
    });
    
    Ext.ms02data.ledadvcommands = [
        ["2", _CommandExpression_LED_DelAllAdvertisement],
        ["3", _CommandExpression_LED_GetAdvertisementCount],
        ["4", _CommandExpression_LED_GetAdvertisement]
    ];
    
    var cmdledadvstore = createSimpleStore('cmdid', 'text', Ext.ms02data.ledadvcommands);
    
    var txtTest = new Ext.form.TextField({});
    var txtMailAddress=createNewParamNumberField(_LED_MailboxNumber, 3,false,'txtMailAddress','txtMailAddress');
    txtMailAddress.setValue(0);
    var cmbLEDAdvCommand = createComboBoxForCommand(false, _LED_Adv_Command, cmdledadvstore, 'cmdid', 'text',false, true, true, 200,
        '<tpl for="."><div class="x-combo-list-item" ext:qtitle="" ext:qtip="{text}">{text}</div></tpl>',
    function() {
        var cmdtext = cmbLEDAdvCommand.getRawValue();
        if(cmdtext == _CommandExpression_LED_DelAllAdvertisement){
            txtMailAddress.setVisible(false);
        }
        else if(cmdtext == _CommandExpression_LED_GetAdvertisementCount){
            txtMailAddress.setVisible(false);
        }
        else if(cmdtext == _CommandExpression_LED_GetAdvertisement){
            txtMailAddress.setVisible(true);
        }
    });
    cmbLEDAdvCommand.setValue("2");
   
    
    Ext.ms02data.ledalarmcommands = [
       ["7", _CommandExpression_LED_SetAlarm],
       ["8",_CommandExpression_LED_ShowAlarm],
       ["9", _CommandExpression_LED_HideAlarm]
    ];
    
    var cmbSetAlarmType = createNewParamCmbField(new Ext.data.ArrayStore({
                    fields: [{name:'valueid',type:'integer'}, 'val'],
                    data: [[0,_LED_AlarmType1],[1,_LED_AlarmType2]]
                }),_LED_RFlag,"");
    cmbSetAlarmType.setWidth(200);
            cmbSetAlarmType.setValue(0);
    var txtAlarmText=createNewParamTextField(_LED_AlarmText, 8,false,"txtAlarmText","txtAlarmText");
    txtAlarmText.setWidth(180);
    txtAlarmText.addListener('keyup',  function(obj,e){
       if (isUnicode(txtAlarmText.getValue()))
            txtAlarmText.maxLength = 8;
        else
            txtAlarmText.maxLength = 16;
   });
    var txtShowAlarmTimeSpan =createNewParamNumberField(_LED_KeepAlarmTimeSpan+"("+_TrackerMain_Second+")", 65535,false,"txtShowAlarmTimeSpan","txtShowAlarmTimeSpan");
    txtShowAlarmTimeSpan.setValue(0);
    var cmdledalarmstore =  createSimpleStore('cmdid', 'text', Ext.ms02data.ledalarmcommands);
     var cmbLEDAlarmCommand = createComboBoxForCommand(false, _LED_AlarmCommand, cmdledalarmstore, 'cmdid', 'text',false, true, true, 200,
        '<tpl for="."><div class="x-combo-list-item" ext:qtitle="" ext:qtip="{text}">{text}</div></tpl>',
    function() {
        var cmdtext = cmbLEDAlarmCommand.getRawValue();
        if(cmdtext == _CommandExpression_LED_ShowAlarm){
            txtShowAlarmTimeSpan = createNewParamNumberField(_LED_KeepAlarmTimeSpan+"("+_TrackerMain_Second+")", 65535,false,"txtShowAlarmTimeSpan","txtShowAlarmTimeSpan");
            txtShowAlarmTimeSpan.setValue(0);
            panelLEDAlarmCommandParams.removeAll();
            panelLEDAlarmCommandParams.add(txtShowAlarmTimeSpan);
            panelLEDAlarmCommandParams.setVisible(true);
            panelLEDAlarmCommandParams.doLayout();
        }
        else if(cmdtext == _CommandExpression_LED_HideAlarm){
            panelLEDAlarmCommandParams.setVisible(false);
        }
        else if(cmdtext == _CommandExpression_LED_SetAlarm){
            panelLEDAlarmCommandParams.removeAll();
            txtAlarmText= createNewParamTextArea(_LED_AlarmText, 255,false,"txtAlarmText","txtAlarmText");
            cmbSetAlarmType = createNewParamCmbField(new Ext.data.ArrayStore({
                    fields: [{name:'valueid',type:'integer'}, 'val'],
                    data: [[0,_LED_AlarmType1],[1,_LED_AlarmType2]]
                }),_LED_RFlag,"");
            
            panelLEDAlarmCommandParams.add(cmbSetAlarmType);
            panelLEDAlarmCommandParams.add(txtAlarmText);
            cmbSetAlarmType.setWidth(200);
            cmbSetAlarmType.setValue(0);
            panelLEDAlarmCommandParams.setVisible(true);
            panelLEDAlarmCommandParams.doLayout();
        }
    });
    cmbLEDAlarmCommand.setValue("7");
    
    

    Ext.ms02data.ledothercommands= [
        ["11", _CommandExpression_LED_GetTime],
        ["12",_CommandExpression_LED_SetTime],
       ["13", _CommandExpression_LED_SetBrightness],
       ["14",_CommandExpression_LED_GetBrightness],
        ["16",_CommandExpression_LED_SearchWorkingStatus],
       ["17",_CommandExpression_LED_TimerSwitch],
       ["18", _CommandExpression_LED_LEDSwitch]
   ];
   
 
   var cmdledotherstore = createSimpleStore('cmdid', 'text', Ext.ms02data.ledothercommands);
   
    var cmbLEDOtherCommand = createComboBoxForCommand(false, _CommandExpression_LED, cmdledotherstore, 'cmdid', 'text',true, true, true, 200,
        '<tpl for="."><div class="x-combo-list-item" ext:qtitle="" ext:qtip="{text}">{text}</div></tpl>',
    function() {
        var cmdtext = cmbLEDOtherCommand.getRawValue();
        if(cmdtext == _CommandExpression_LED_SetTime){
            reshowledparams();
            var d= createNewParamAndShow(EnumParamFieldType.Date,_LED_SetDate,0,"",null,'','correctdate');
            d.allowBlank = false;
            d.format = "Y-m-d";
            var t= createNewParamAndShow(EnumParamFieldType.Time,_LED_SetTime,0,"",null,'','correcttime');
            t.format = "H:i:s";
            t.allowBlank = false;
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_GetTime){
            reshowledparams();
            redoledlayoutparams();
        }
         else if(cmdtext == _CommandExpression_LED_SetBrightness){
            reshowledparams();
            var stotype = new Ext.data.ArrayStore({
                fields: [{name:'valueid',type:'integer'}, 'val'],
                data: [[0,_LED_LightType1]]//,[1,_LED_LightType2],[2,_LED_LightType3]]
            });
            cmbparams1 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightControlType, 0, "", stotype);
            cmbparams2 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightValue, 0, "", getIndexStore(0,15));
            
            cmbparams1.addListener('select',function(obj,record,index){
                if(index == 1){
                    b1.setVisible(true);
                    b2.setVisible(true);
                    b3.setVisible(true);
                    b4.setVisible(true);
                    cmbparams3.setVisible(true);
                    cmbparams4.setVisible(true);
                    cmbparams5.setVisible(true);
                    cmbparams6.setVisible(true);
                }
                else{
                    b1.setVisible(false);
                    b2.setVisible(false);
                    b3.setVisible(false);
                    b4.setVisible(false);
                    cmbparams3.setVisible(false);
                    cmbparams4.setVisible(false);
                    cmbparams5.setVisible(false);
                    cmbparams6.setVisible(false);
                }
            });
            var b1 = createNewParamAndShow(EnumParamFieldType.Time,_LED_LightControlTime+"1",0,"",null,'','btime1');
            b1.setValue("00:00");
            cmbparams3 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightValue+"1", 0, "", getIndexStore(0,15)); 
            var b2 =createNewParamAndShow(EnumParamFieldType.Time,_LED_LightControlTime+"2",0,"",null,'','btime2');
            b2.setValue("00:00");
            cmbparams4 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightValue+"2", 0, "", getIndexStore(0,15)); 
            var b3 =createNewParamAndShow(EnumParamFieldType.Time,_LED_LightControlTime+"3",0,"",null,'','btime3');
            b3.setValue("00:00");
            cmbparams5 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightValue+"3", 0, "", getIndexStore(0,15)); 
            var b4 =createNewParamAndShow(EnumParamFieldType.Time,_LED_LightControlTime+"4",0,"",null,'','btime4');
            b4.setValue("00:00");
            cmbparams6 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_LightValue+"4", 0, "", getIndexStore(0,15)); 
            
            b1.setVisible(false);
            b2.setVisible(false);
            b3.setVisible(false);
            b4.setVisible(false);
            cmbparams3.setVisible(false);
            cmbparams4.setVisible(false);
            cmbparams5.setVisible(false);
            cmbparams6.setVisible(false);
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_GetBrightness){
            reshowledparams();
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_SetPowerOnWaitingTime){
            reshowledparams();
            txtparams1 = createNewParamAndShow(EnumParamFieldType.NumberField,_LED_Time,255,_TrackerMain_Seconds,null);
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_SearchWorkingStatus){
            reshowledparams();
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_TimerSwitch){
            reshowledparams();
            cmbparams1 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, _LED_WorkModel, 0, "", new Ext.data.ArrayStore({
                fields:['valueid','val'],
                data:[['0',_LED_WorkAllDay],['1',_LED_WorkOnTime]]
            }));
            var b1 = createNewParamAndShow(EnumParamFieldType.Time, _LED_StartTimeSpan, 0, "", null, '', 'workbegintime');
            var b2 = createNewParamAndShow(EnumParamFieldType.Time, _LED_StopTimeSpan, 0, "", null, '', 'workendtime');
            b1.setValue("00:00");
            b2.setValue("23:59");
            b1.setVisible(false);
            b2.setVisible(false);
            cmbparams1.addListener('select', function(obj, record, index) {
                if (index == 0) {
                    b1.setVisible(false);
                    b2.setVisible(false);
                }
                else {
                    b1.setVisible(true);
                    b2.setVisible(true);
                }
            });
            redoledlayoutparams();
        }
        else if(cmdtext == _CommandExpression_LED_LEDSwitch){
            reshowledparams();
            panelledparams.show();
            cmbparams1 = createNewParamAndShow(EnumParamFieldType.ComboBoxField, "", 0, "", new Ext.data.ArrayStore({
                fields: ['valueid', 'val'],
                data: [['0',_LED_Close],['1',_LED_Open],['2',_LED_Reset]]
            }));
            redoledlayoutparams();
        }
    });
    cmbLEDOtherCommand.setValue("11");
    
    function getSSSIDS(){
        var sssids ="";
        var records = grdTrackerList.getSelectionModel().getSelections();
        var i;
        for(i=0;i<records.length;i++){
            if(sssids == ""){
                sssids = records[i].get('snid');
            }
            else
                sssids += records[i].get('snid');
        }
        return sssids;
    }
    
    function getSSSIDSFromRecords(records){
         var sssids ="";
         var i;
        for(i=0;i<records.length;i++){
            if(sssids == ""){
                sssids = records.get('snid');
            }
            else
                sssids += records.get('snid');
        }
        return sssids;
    }
    
    function addLEDCommand(mt88param){
        var records = grdTrackerList.getSelectionModel().getSelections();
        var i=0;
        var mt88cmd = EnumMT88Command.EXT_LED_Command;
        var gvvtcommand = EnumGPRSCommand.NotSupportThisCommand;
        var gvvtparam = "";
        var gbcommand = "";
        var gbparam = 0;
        if(records.length>0){
            for(i=0;i<records.length;i++){
                var record = records[i];
                var sssid = record.get('snid');
                if (sssid != ""){
                    record.set('process',_TrackerMain_Sending);
                    addOneTCPCommand(sssid, gvvtcommand, gvvtparam, mt88cmd, mt88param, gbcommand, gbparam);
                }
            }
        }
        else{
            Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
            Ext.Msg.show({
                title: _POI_SelectAtLeastOne,
                msg: _POI_SelectAtLeastOne,
                buttons: Ext.Msg.OK,
                animEl: 'elId',
                icon: Ext.MessageBox.WARNING
            });
        }
    }
    
    var btnAdvSendCommand = new Ext.Button({
        text: _TrackerMain_Send,
        style: 'padding-left:16px',
        width: 80,
        handler: function() {
            var cmdtext = cmbLEDAdvCommand.getRawValue();
            var mt88param ="";
            if(cmdtext == _CommandExpression_LED_DelAllAdvertisement){
                Ext.MessageBox.YESNO = { yes: _TrackerMain_Yes, no: _TrackerMain_No };
                Ext.MessageBox.confirm(_TrackerMain_Title, _LED_Sure_Del_All_Adv, function(btn){
                    if (btn == "yes") {
                        mt88param = getLEDFullHexString(EnumLEDCommand.DelAllAdv, "");
                        addLEDCommand(mt88param);
                    }
                });
            }
            else if(cmdtext == _CommandExpression_LED_GetAdvertisementCount){
                mt88param = getLEDFullHexString(EnumLEDCommand.GetAdvCount, "");
                addLEDCommand(mt88param);
            }
            else if(cmdtext == _CommandExpression_LED_GetAdvertisement){
                mt88param = getLEDFullHexString(EnumLEDCommand.GetOneAdv, UInt8ToByteString(txtMailAddress.getValue()));
                addLEDCommand(mt88param);
            }
                
        }
    });
            
    var btnImmiSendCommand = new Ext.Button({
        text: _CommandExpression_LED_SendMessage,
        style: 'padding-left:16px',
        width: 80,
        handler: function() {
            var sssids = getSSSIDS();
            var t = Ext.getCmp('sendmessagedate').getEl().dom.value;
            var tmp = t.split(':');
            var tseconds = parseInt(tmp[0]) * 3600 + parseInt(tmp[1]) * 60;
            
            Ext.Ajax.request({
                url: 'HandlerLEDSettings',
                method: 'post',
                params:{
                    event:"update",
                    type:"immi",
                    sssids:sssids,
                    color:1,
                    font:cmbImmiFont.getValue(),
                    moving:cmbImmiMove.getValue(),
                    speed:cmbImmiSpeed.getValue(),
                    exitway:cmbImmiExitModel.getValue(),
                    level:cmbImmiShowLevel.getValue(),
                    stay_time:txtImmiKeepTime.getValue(),
                    stop_model:cmbImmiStopModel.getValue(),
                    immi_msg:txtImmiBody.getValue(),
                    lifetime:datImmiLifeTime.getValue(),
                    showtime:txtImmiShowTime.getValue(),
                    showtimes:txtImmiShowTimes.getValue()
                },
                success:function(resp,opts) {   
                    var bodyhex = UInt8ToByteString(cmbImmiShowLevel.getValue()) + UInt8ToByteString(cmbImmiExitModel.getValue());
                    var t = Ext.getCmp('sendmessagedate').getEl().dom.value;
                    var tmp = t.split(':');
                    var tseconds = parseInt(tmp[0]) * 3600 + parseInt(tmp[1]) * 60;
                    bodyhex += UInt32ToDWORDStringNoComm(tseconds);
                    bodyhex += UInt16ToWORDStringNoComm(txtImmiShowTime.getValue());
                    bodyhex += UInt8ToByteString(txtImmiShowTimes.getValue());
                    bodyhex += UInt8ToByteString(cmbImmiFont.getValue()) + UInt8ToByteString(1) + //Color 取消
                    UInt8ToByteString(cmbImmiMove.getValue()) + UInt8ToByteString(cmbImmiSpeed.getValue()) + UInt8ToByteString(txtImmiKeepTime.getValue()) + UInt8ToByteString(cmbImmiStopModel.getValue());
                    bodyhex += UInt8ToByteString(Math.floor(Math.random() * 0xFF));
                    //var txthex = encodeGBKNoComm(ToDBC(txtparams5.getValue()));
                    txthex = encodeGBKNoComm(txtImmiBody.getValue());
                    var mt88param = getLEDFullHexString(EnumLEDCommand.SendImmeMsg, bodyhex + txthex);
                    addLEDCommand(mt88param);
                }
            });
        }
    });
    
        
    var btnBreakImmiCommand = new Ext.Button({
        text: _CommandExpression_LED_BreakMessage,
        style: 'padding-left:16px',
        width: 80,
        handler: function() {
            var mt88param = getLEDFullHexString(EnumLEDCommand.StopImmeMsg, "");
            addLEDCommand(mt88param);
        }
    }); 
    
    var btnSetDefaultText = new Ext.Button({
        text: _LED_ShowDefaultText,
        style: 'padding-left:16px',
        width: 80,
        handler: function() {
            Ext.Ajax.request({
                url: 'HandlerLEDSettings',
                method: 'post',
                params:{
                    event:"update",
                    type:"default",
                    sssids:getSSSIDS(),
                    color:1,
                    font:cmbdefaultfont.getValue(),
                    moving:cmbdefaultmove.getValue(),
                    speed:cmbdefaultspeed.getValue(),
                    showtype:1,
                    stay_time:txtdefaultkeeptime.getValue(),
                    stop_model:cmbdefaultstopmodel.getValue(),
                    default_msg:txtdefaultbody.getValue()
                },
                success:function(resp,opts) { 
                    var mt88param;
                    var bodyhex = UInt8ToByteString(1) +
                                UInt8ToByteString(cmbdefaultfont.getValue())+
                                UInt8ToByteString(1) +
                                UInt8ToByteString(cmbdefaultmove.getValue()) +
                                UInt8ToByteString(cmbdefaultspeed.getValue()) +
                                UInt8ToByteString(txtdefaultkeeptime.getValue()) +
                                UInt8ToByteString(cmbdefaultstopmodel.getValue());
                           
                    var txthex = encodeGBKNoComm(txtdefaultbody.getValue());
                    mt88param = getLEDFullHexString(EnumLEDCommand.SetDefaultMsg, bodyhex + txthex);
                    addLEDCommand(mt88param);
                }
            });
        
        }
    });
    
    var btnSetDefaultAsSysTime = new Ext.Button({
        text: _LED_ShowSysTime,
        style: 'padding-left:16px',
        width: 80,
        handler: function() {
            Ext.Ajax.request({
                url: 'HandlerLEDSettings',
                method: 'post',
                params:{
                    event:"update",
                    type:"default",
                    sssids:getSSSIDS(),
                    color:1,
                    font:cmbdefaultfont.getValue(),
                    moving:cmbdefaultmove.getValue(),
                    speed:cmbdefaultspeed.getValue(),
                    showtype:0,
                    stay_time:txtdefaultkeeptime.getValue(),
                    stop_model:cmbdefaultstopmodel.getValue(),
                    default_msg:txtdefaultbody.getValue()
                },
                success:function(resp,opts) { 
                    var mt88param;
                    var bodyhex = UInt8ToByteString(0) +
                               
                                UInt8ToByteString(cmbdefaultfont.getValue()) +
                                 UInt8ToByteString(1) +
                                UInt8ToByteString(cmbdefaultmove.getValue()) +
                                UInt8ToByteString(cmbdefaultspeed.getValue()) +
                                UInt8ToByteString(txtdefaultkeeptime.getValue()) +
                                UInt8ToByteString(cmbdefaultstopmodel.getValue());
                           
                    var txthex = encodeGBKNoComm(txtdefaultbody.getValue());
                    mt88param = getLEDFullHexString(EnumLEDCommand.SetDefaultMsg, bodyhex + txthex);
                    addLEDCommand(mt88param);
                }
            });
        }
    });
    
    var btnAlarmSendCommand = new Ext.Button({
        text:_TrackerMain_Send,
        style:'padding-left:16px',
        width:80,
        handler:function(){
            var cmdtext = cmbLEDAlarmCommand.getRawValue();
            if(cmdtext == _CommandExpression_LED_SetAlarm){
                var toolong = false;
                if (isUnicode(txtAlarmText.getValue())){
                   if(txtAlarmText.getValue().length>8)
                    toolong = true;
                }
                else {
                    if(txtAlarmText.getValue().length>16)
                        toolong = true;
                }
                if(!toolong){
                    Ext.Ajax.request({
                        url: 'HandlerLEDSettings',
                        method: 'post',
                        params:{
                            event:"update",
                            type:"alarm",
                            sssids:getSSSIDS(),
                            show_alarm_type:cmbSetAlarmType.getValue(),
                            alarm_msg:txtAlarmText.getValue()
                            
                        },
                        success:function(resp,opts) { 
                            var bodyhex = UInt8ToByteString(cmbSetAlarmType.getValue());
                            var txthex = padRight(encodeGBKNoComm(txtAlarmText.getValue()), '20', 32);
                            var mt88param = getLEDFullHexString(EnumLEDCommand.SetAlarmMsg, bodyhex + txthex);
                            addLEDCommand(mt88param);
                        }
                    });
                }else{
                    Ext.MessageBox.buttonText.ok = _CustomerConfigResource_OK;
                    Ext.Msg.show({
                        title: _CustomerConfigResource_Tip,
                        msg:  _NewForText_LengthMustBetween + (isUnicode(txtAlarmText.getValue())?" 0-8":" 0-16"),
                        buttons: Ext.Msg.OK,
                        animEl: 'elId',
                        icon: Ext.MessageBox.INFO
                    });
                }
            }
            else{
                var mt88param;
                if(cmdtext == _CommandExpression_LED_ShowAlarm){
                    mt88param = getLEDFullHexString(EnumLEDCommand.ShowAlarmMsg, UInt16ToWORDStringNoComm(txtShowAlarmTimeSpan.getValue()));
                }
                else if(cmdtext == _CommandExpression_LED_HideAlarm){
                    mt88param = getLEDFullHexString(EnumLEDCommand.HideAlarmMsg, "");
                }
                addLEDCommand(mt88param);
                
            }
        }
    });
    
       
    var btnSendLEDOtherCommand =  new Ext.Button({
        id: 'ledsendothercommand',
        text: _TrackerMain_Send,
        handler: function() {
            cmdledtext = cmbLEDOtherCommand.getRawValue();
            var mt88param="";
            if (cmdledtext == _CommandExpression_LED_SetTime) {
                var s = Ext.getCmp('correctdate').getEl().dom.value +
                     ' ' + Ext.getCmp('correcttime').getEl().dom.value;
                var dtime = new Date(Date.parse(s.replace(/-/g, "/")));
                var bodyhex = UInt8ToByteString(dtime.getFullYear() - 2000) + UInt8ToByteString(dtime.getMonth() + 1) + UInt8ToByteString(dtime.getDate()) + UInt8ToByteString(dtime.getDay())
                    + UInt8ToByteString(dtime.getHours()) + UInt8ToByteString(dtime.getMinutes()) + UInt8ToByteString(dtime.getSeconds());
                mt88param = getLEDFullHexString(EnumLEDCommand.SetTime, bodyhex);

            }
            else if (cmdledtext == _CommandExpression_LED_GetTime) {
                mt88param = getLEDFullHexString(EnumLEDCommand.GetTime, "");
            }
            else if (cmdledtext == _CommandExpression_LED_SetBrightness) {
                var bodyhex = UInt8ToByteString(cmbparams1.getValue()) + UInt8ToByteString(cmbparams2.getValue());
                var time1 = UInt16ToWORDStringNoComm(timerToSeconds(Ext.getCmp('btime1').getValue()));
                var time2 = UInt16ToWORDStringNoComm(timerToSeconds(Ext.getCmp('btime2').getValue()));
                var time3 = UInt16ToWORDStringNoComm(timerToSeconds(Ext.getCmp('btime3').getValue()));
                var time4 = UInt16ToWORDStringNoComm(timerToSeconds(Ext.getCmp('btime4').getValue()));
                var v1 = UInt8ToByteString(cmbparams3.getValue());
                var v2 = UInt8ToByteString(cmbparams4.getValue());
                var v3 = UInt8ToByteString(cmbparams5.getValue());
                var v4 = UInt8ToByteString(cmbparams6.getValue());
                mt88param = getLEDFullHexString(EnumLEDCommand.SetLightLevel, bodyhex + time1 + time2 + time3 + time4 + v1 + v2 + v3 + v4);
            }
            else if (cmdledtext == _CommandExpression_LED_GetBrightness) {
                mt88param = getLEDFullHexString(EnumLEDCommand.GetLightLevel, "");
            }
            else if (cmdledtext == _CommandExpression_LED_SetPowerOnWaitingTime) {
                var bodyhex = padLeft(txtparams1.getValue().toString(16), '0', 2);
                mt88param = getLEDFullHexString(EnumLEDCommand.SetPowerOnWaitTime, bodyhex);
            }
            else if (cmdledtext == _CommandExpression_LED_SearchWorkingStatus) {
                mt88param = getLEDFullHexString(EnumLEDCommand.GetWorkState, "");
            }
            else if (cmdledtext == _CommandExpression_LED_TimerSwitch) {
                var bodyhex = UInt8ToByteString(cmbparams1.getValue());
                var timebegin = Ext.getCmp('workbegintime').getValue();
                var timeend = Ext.getCmp('workendtime').getValue();
                var tbegin = timerToSeconds(timebegin);
                var tend = timerToSeconds(timeend);
                mt88param = getLEDFullHexString(EnumLEDCommand.SetAutoPowerOnOffTime, bodyhex + UInt16ToWORDStringNoComm(tbegin) + UInt16ToWORDStringNoComm(tend));
            }
            else if (cmdledtext == _CommandExpression_LED_LEDSwitch) {
                var bodyhex = UInt8ToByteString(cmbparams1.getValue());
                mt88param = getLEDFullHexString(EnumLEDCommand.SetLED, bodyhex);
            }
            addLEDCommand(mt88param);        
        }
    });
    
    var panelLEDAdvCommandParams = new Ext.Panel({
        border:false,
        layout:'form',
        items:[txtMailAddress],
        buttonAlign:'center',
        buttons:[btnAdvSendCommand]
    });
    txtMailAddress.setVisible(false);
    txtMailAddress.setMaxValue(255);
    txtMailAddress.setMinValue(0);
    
    var panelLEDAdvCommand = new Ext.Panel({
        region:'south',
        border:false,
        layout:'form',
        bodyStyle:"padding-top:8px;padding-left:5px",
        split:false,
        
        items:[cmbLEDAdvCommand,panelLEDAdvCommandParams]
    });
    
    var stoimmitype = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[0,_LED_Normal],[1,_LED_Urgent]]
    });
    var cmbImmiShowLevel = createNewParamCmbField(stoimmitype,_LED_ShowLevel, "");
    cmbImmiShowLevel.setValue(0);    
    var stoexittype = new Ext.data.ArrayStore({
        fields: [{name:'valueid',type:'integer'}, 'val'],
        data: [[0,_LED_ExitType1],[1,_LED_ExitType2],[2,_LED_ExitType3],[3,_LED_ExitType4]] //,[4,_LED_ExitType5]]
    });
    var cmbImmiExitModel = createNewParamCmbField(stoexittype, _LED_ExitModel, "");
    cmbImmiExitModel.setValue(0);
    var datImmiLifeTime=createNewParamTime(_LED_LifeTime,false,'sendmessagedate','sendmessagedate');
    datImmiLifeTime.setValue("00:00");
    var  txtImmiShowTime = createNewParamNumberField(_LED_ImmiShowTime, 3, false);//播放时间
    txtImmiShowTime.setValue(0);
    var txtImmiShowTimes = createNewParamNumberField(_LED_ShowTimes,3,false);//
    txtImmiShowTimes.setValue(0);
    
    var cmbImmiFont = createNewParamCmbField(stofont, _LED_Font);
    cmbImmiFont.setValue(0);
    //var cmbImmiColor = createNewParamAndShow(stocolor, _Color);
    var cmbImmiMove = createNewParamCmbField(stomove,_LED_MoveDirection);
    cmbImmiMove.setValue(1);
    var cmbImmiSpeed = createNewParamCmbField(stospeed,_LED_Speed);
    cmbImmiSpeed.setValue(0);
    var txtImmiKeepTime = createNewParamNumberField(_LED_KeepTime, 3);
    txtImmiKeepTime.setValue(0);
    txtImmiKeepTime.setMaxValue(255);
    txtImmiKeepTime.setMinValue(0);
    var cmbImmiStopModel = createNewParamCmbField(stostoptype,_LED_StopModel);
    cmbImmiStopModel.setValue(0);
    var txtImmiBody= createNewParamTextArea( _LED_Body, 255, "", null);
    txtImmiBody.setWidth(150);
    //txtparams3 = createNewParamAndShow(EnumParamFieldType.NumberField, "信息 ID号", 255, "s",null);
    
    datImmiLifeTime.setVisible(false);
    txtImmiShowTime.setVisible(false);
    txtImmiShowTimes.setVisible(false);
    cmbImmiExitModel.addListener('select',function(obj,record,index){
        if(index == 0){
            datImmiLifeTime.setVisible(false);
            txtImmiShowTime.setVisible(false);
            txtImmiShowTimes.setVisible(false);
        }
        else if(index ==1){
            datImmiLifeTime.setVisible(true);
            txtImmiShowTime.setVisible(false);
            txtImmiShowTimes.setVisible(false);
        }
        else if(index == 2){
            datImmiLifeTime.setVisible(false);
            txtImmiShowTime.setVisible(true);
            txtImmiShowTimes.setVisible(false);
        }
        else if(index == 3){
            datImmiLifeTime.setVisible(false);
            txtImmiShowTime.setVisible(false);
            txtImmiShowTimes.setVisible(true);
        }
        else if(index == 4){
            datImmiLifeTime.setVisible(true);
            txtImmiShowTime.setVisible(false);
            txtImmiShowTimes.setVisible(false);
        }
    });
        
     var panelImmiMsgCommand= new Ext.Panel({
        region:'east',
        layout:'form',
        split: false,
        collapsible: false,
        buttonAlign:'center',
        height:'auto',
        items:[cmbImmiShowLevel,cmbImmiExitModel,datImmiLifeTime,txtImmiShowTime,txtImmiShowTimes,cmbImmiFont,cmbImmiMove,cmbImmiSpeed,txtImmiKeepTime,cmbImmiStopModel,txtImmiBody],
        buttons:[btnImmiSendCommand,btnBreakImmiCommand]
    });
    
    var panelLEDAdv = new Ext.Panel({
        id:'panelLEDAdv',
        title: _LED_Adv_Define,
        layout:'border',
        items:[grdAdv]
    });
    
    var panelLEDImmiMsg = new Ext.Panel({
        id:'panelLEDImmiMsg',
        title: _LED_Immi,
        layout:'border',
        items:[grdImmiMsg]
    });
    
    var cmbdefaultfont = createNewParamCmbField(stofont, _LED_Font);
    cmbdefaultfont.setValue(0);
    var cmbdefaultcolor = createNewParamCmbField(stocolor, _Color);
    var cmbdefaultmove = createNewParamCmbField(stomove, _LED_MoveDirection);
    cmbdefaultmove.setValue(1);
    var cmbdefaultspeed = createNewParamCmbField(stospeed, _LED_Speed);
    cmbdefaultspeed.setValue(0);
    var txtdefaultkeeptime = createNewParamNumberField(_LED_KeepTime, 3);
    txtdefaultkeeptime.setValue(0);
    txtdefaultkeeptime.setMinValue(0);
    txtdefaultkeeptime.setMaxValue(255);
    var cmbdefaultstopmodel = createNewParamCmbField(stostoptype, _LED_StopModel);
    cmbdefaultstopmodel.setValue(0);
    var txtdefaultbody = createNewParamTextArea(_NewForText_ValueText, 128);
    txtdefaultbody.setHeight(150);
    txtdefaultbody.setWidth(150);
    
    var panelDefaultMsgCommand = new Ext.Panel({
        region:'east',
        layout:'form',
        split: false,
        collapsible: false,
        border:false,
        height:260,
        buttonAlign:'center',
        items:[cmbdefaultfont,cmbdefaultmove,cmbdefaultspeed,txtdefaultkeeptime,cmbdefaultstopmodel,txtdefaultbody],
        buttons:[btnSetDefaultText,btnSetDefaultAsSysTime]
    });
    
    var panelLEDDefaultMsg = new Ext.Panel({
        id:'panelLEDDefaultMsg',
        title: _LED_DefaultText,
        layout:'border',
        items:[grdDefaultMsg]
    });
    
    var panelLEDAlarmCommandParams = new Ext.Panel({
        border:false,
        layout:'form',
        height:150,
        items:[cmbSetAlarmType,txtAlarmText]
    });
    
    var panelAlarmMsgCommand = new Ext.Panel({
        region:'south',
        border:false,
        bodyStyle:"padding-top:8px;padding-left:10px",
        layout:'form',
        height:260,
        buttonAlign:'center',
        items:[cmbLEDAlarmCommand, panelLEDAlarmCommandParams],
        buttons:[btnAlarmSendCommand]
    });
    
    var panelLEDAlarmMsg = new Ext.Panel({
        id:'panelLEDAlarmMsg',
        title:_LED_Alarm,
        layout:'border',
        items:[grdAlarmMsg]
    });
    
    var panelTab = new Ext.TabPanel({
        id: 'panelLEDTab',
        region:'center',
        activeTab: 0,
        split: true,
        collapsible: false,
        width: 900,
        height:300,
        items: [panelLEDAdv,panelLEDImmiMsg,panelLEDDefaultMsg,panelLEDAlarmMsg]
    });
    
    var loading = true;
    panelTab.addListener('tabchange',function(obj,tab ){
        var activeTab = panelTab.getActiveTab();
        var activeTabIndex = panelTab.items.findIndex('id', activeTab.id);
        if(!loading)
            panelLEDOther.collapse();
        panelTabCommand.setActiveTab(activeTabIndex);
    });
    
    var leddevicestore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'HandlerSearchTrackerName',
            timeout: 240000
        }),
        reader: new Ext.data.JsonReader({
            fields: ["trackname", "snid","process"],
            root: "data"
        })
    });
    
    leddevicestore.load();
    var timer1 =null;
    var txtSearchLEDDeviceKey = new Ext.form.TextField({
        width:300,
        allowBlank: true,
        maxLength: 32,
        emptyText: _TrackerMain_Search,
        maxText: _Message_MaxText+' 32',
        enableKeyEvents:true
    });
    
  

    var devtoolbaritems = [
        txtSearchLEDDeviceKey
        ,{
            tooltip: { text: _TrackerMain_Search, autoHide: true },
            icon: 'images/search16.gif',
            handler: function() {
                var k = txtSearchLEDDeviceKey.getValue();
                leddevicestore.filter('trackname',k,true);
            }
        }
    ];
    
    var timersearch = null;
    txtSearchLEDDeviceKey.addListener('keydown',function(obj,e){
        if(timersearch != null)
            clearTimeout(timersearch);
        timersearch = setTimeout(function(){
            var k = txtSearchLEDDeviceKey.getValue();
            leddevicestore.filter('trackname',k,true);
        },2000);
   });
    
    var smLEDCommand = new Ext.grid.CheckboxSelectionModel();

    var grdTrackerList = new Ext.grid.GridPanel({
        tbar:devtoolbaritems,
        split: true,  
        collapsible: false,
        region:'center',
        store:leddevicestore,
        colModel: new Ext.grid.ColumnModel({
            defaults: {
                width: 120,
                sortable: true,
                menuDisabled: true
            },
            columns: [
                smLEDCommand,
                {header: _TrackerMain_TrackerName, hidden:false,width: 200, sortable: true, dataIndex: 'trackname'},
                {header:_TrackerMain_Process,width:200,sortable: true, dataIndex: 'process'}
            ],
        }),
        sm: smLEDCommand,
        frame: true,
        //title: _TrackerMain_Devices,
        iconCls: 'icon-grid'
    });
    
    var panelledcmdlist = createPanelForCommand(null, 'form', false, 300, 40, 70, [cmbLEDOtherCommand], null, null, 'padding-top:10px,padding-left:10px');
    var panelledparams = createPanelForCommand('panelledparams', 'table', false, 350,180,null,[panelledparamscolumn1],2,null,null,true);
    var panelledallcommand = createPanelForCommand('panelledallcommand', 'form', false, 390,null,70, [panelledcmdlist,panelledparams], null, 'center');
    panelledallcommand.addButton(btnSendLEDOtherCommand);
    
    
    var panelLEDOther = new Ext.Panel({
        //id:'panelLEDOther',
        split:true,
        
        collapsible:true,
        title:_LED_OtherCommand,
        width:360,
        border:true
        ,layout:'form'
        ,region:'west'
        ,items:[panelledallcommand]
    });
    
    var panelTabCommand = new Ext.TabPanel({
        id: 'panelTabCommand',
        region:'center',
        activeTab: 0,
        split: true,
        collapsible: false,
        border:true,
        headerStyle : 'display: none', 
        width:320,
        items: [panelLEDAdvCommand,panelImmiMsgCommand,panelDefaultMsgCommand,panelAlarmMsgCommand]
    });
    
    var panelLEDCommand  = new Ext.Panel({
        split:true,
        height:310,
        width:100,
        region:'south',
        layout:'border',
        items:[panelLEDOther,panelTabCommand]
    });

    var panelLEDWest = new Ext.Panel({
        layout:'border',
        collapsible: true,     
        region:'west',
        split:false,
        width:360,
        title: _TrackerMain_Devices,
        items:[grdTrackerList,panelLEDCommand]
    });
    
    var panelLED = new Ext.Panel({
        id: 'panelLED',
        layout:'border',
        border:false,
        split: true,
        items: [panelTab,panelLEDWest]
    });
    
    var ledwin = new Ext.Window({
        title: _LED_Settings,
        layout: 'fit',
        height: 600,
        width: 1100,
        items: panelLED,
        iconCls:'icon-ledadv',
        closeAction: 'close',
        minimizable: true,
        constrain:true,
        
        listeners: {
            'minimize': function() {
                addTaskButtonForWindow(ledwin);
            }
        }
    });
    
   
    
    ledadvstore.on('beforeload', function(store) {
        store.baseParams = {
            sssids: "",
            start: 'start',
            limit: 'limit'
            
        }
    });
    
    function updateLEDAdv() {
        var record = grdAdv.getSelectionModel().getSelections()[0];

        Ext.MessageBox.show({
            msg: _CustomerConfigResource_Saving,
            progressText: _CustomerConfigResource_Saving,
            width: 300,
            wait: true,
            waitConfig: { interval: 200 }
        });
       
        Ext.Ajax.request({
            url: 'HandlerLEDAdv',
            success: function(result) {
                Ext.MessageBox.hide();
                adveditor.stopEditing();
                var flag = eval(result.responseText);
                if (flag == true) {
                    msgUpdateSuccess();
                }
                else {
                    msgUpdateFailure();
                }
            },
            failure: function() {
                Ext.MessageBox.hide();
                msgUpdateFailure();
            },
            params: {
                event:"update",
                advid:record.data.led_adv_id,
                color:record.data.color,
                font:record.data.font,
                timespan:"",
                moving:record.data.moving,
                msg_show_time_span:record.data.msg_show_time_span,
                speed:record.data.speed,
                start_date:record.data.start_date,
                stay_time:record.data.stay_time,
                stop_date:record.data.stop_date,
                stop_model:record.data.stop_model,
                text:record.data.text
            }
        })
       
    }

    this.removeLEDAdv = function(sssid, ledadddress){
        var index = ledadvstore.findBy(function(record,id){
            return record.get("sssid") == sssid && record.get("adv_address")== parseInt(ledadddress);
        });
        if(index != -1)
            ledadvstore.remove(record);
//        try{
//            ledadvstore.each(function(record){
//                if(record.get("sssid") == sssid && record.get("adv_address")== parseInt(ledadddress)){
//                    ledadvstore.remove(record);
//                    return;
//                }
//            });
//        }catch(err)
//        {
//        
//        }
    };
    
    this.changeProcess= function(sssid,processstr){
        var index = leddevicestore.findBy(function(record,id){
            return record.get("snid") == sssid ;
        });
        if(index != -1){
            var record = leddevicestore.getAt(index);
            record.set('process',processstr);
        }
    }
        
    ledwin.show();
    
    
        loading = false;
   
    
    ledwin.on('close',function(obj){
        g_LEDWindowObject = null;
    });
    
    g_LEDWindowObject = this;
}